﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace FunasrSTT.Translate.Converters;

/// <summary>
/// 转换 Boolean 成是否可见状态.
/// </summary>
public class BooleanToVisibilityConverter : IValueConverter
{
    /// <inheritdoc />
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is bool visibility)
        {
            return visibility ? Visibility.Visible : Visibility.Collapsed;
        }

        return Visibility.Visible;
    }

    /// <inheritdoc />
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is Visibility visibility)
        {
            return visibility switch
            {
                Visibility.Visible => true, _ => false
            };
        }

        return false;
    }
}
